// 使用队列：方块舞的舞伴分配问题
const Queue = require("./queueDefine");
const persons = require('./persons')
class Dancer {
  constructor(name,sex) {
    this.name = name;
    this.sex = sex;
  }
}
// 获取舞者 排成两个队列
const maelDancers = new Queue()//男舞者
const fmaelDancers = new Queue()//女舞者
persons.forEach(item=>{
  const dancer = new Dancer(item.name,item.sex)
  if(item.sex === '男'){
    maelDancers.enqueue(dancer)
  }else if(item.sex === "女"){
    fmaelDancers.enqueue(dancer)
  }
})
// 将男性和女性组成舞伴，并且宣布配对结果
function getDancer(){
  while(!maelDancers.isEmpty()&& !fmaelDancers.isEmpty()){
    console.log("男舞者是：" ,maelDancers.dequeue().name,  "=====>>","女舞者是：" ,fmaelDancers.dequeue().name)
  }
  if(!maelDancers.isEmpty()){
    const dancer = maelDancers.front()
    console.log("当前等待跳舞的男舞者是：",dancer.name)
    console.log("总共有：",maelDancers.count(),"人等待女舞伴")
  }
  if(!fmaelDancers.isEmpty()){
    const dancer = fmaelDancers.front()
    console.log("当前等待跳舞的女舞者是：",dancer.name)
    console.log("总共有：",fmaelDancers.count(),"人等待男舞伴")
  }
}


// 测试
// console.log("男舞者--------",maelDancer)
// console.log("女舞者--------",fmaelDancer)
getDancer()